<?php 

/**
* 
*/
class UserModel extends Model{
	// 设置模型对象
	public $table="user";
	// 存储错误信息
	public $error="";
	// 存储登录后信息
	public $userinfo="";
	/**
	 * [login_check 登录信息检测]
	 * @return [type] [description]
	 */
	public function login_check(){
		// 判断验证码是否正确
		if(session("code")!==Q("post.code",NULL,"strtoupper")){
			$this->error="验证码错误";
			return false;	
		}
		// 判断用户名是否存在
		$username=Q("post.username");
		$userinfo = $this->where(array("username"=>$username))->find();
		if(!$userinfo){
			$this->error="用户名不存在";
			return false;		
		}
		// 判断密码是否正确
		$password=md5(Q("post.password"));
		if($userinfo["password"]!==$password){
			$this->error="密码不正确";
			return false;	
		}
		// 验证成功后把信息传给属性
		$this->userinfo=$userinfo;
		return true;
	}
	/**
	 * [get_data 获取用户数据]
	 * @param  [type] $where [description]
	 * @param  [type] $limit [description]
	 * @return [type]        [description]
	 */
	public function get_data($where=NULL,$limit=NULL){
		return $this->where($where)->limit($limit)->all();
	}
	/**
	 * [get_one_data 获取一条用户数据]
	 * @param  string $value [description]
	 * @return [type]        [description]
	 */
	public function get_one_data($where=NULL,$limit=NULL){
		return $this->where($where)->limit($limit)->find();
	}
	/**
	 * [delete_data 删除用户数据库]
	 * @param  [type] $where [description]
	 * @return [type]        [description]
	 */
	public function delete_data($where=NULL){
		$this->where($where)->delete();
	}
	public function change_stat($where=NULL,$data=NULL){
		$this->where($where)->update($data);
	}
	public function add_data($value=''){
		$this->data["username"] =Q("post.username");
		$this->data["password"] =md5(Q("post.password_reg1"));
		$this->data["nickname"] =Q("post.nickname");
 		$this->add();
	}
	public function add_qqData($data){
		return $this->add($data);
	}


}


 ?>